package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ExamSubject;
import com.ruoyi.system.service.IExamSubjectService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 面试考题记录Controller
 * 
 * @author ruoyi
 * @date 2021-12-03
 */
@Controller
@RequestMapping("/system/subject")
public class ExamSubjectController extends BaseController
{
    private String prefix = "system/subject";

    @Autowired
    private IExamSubjectService examSubjectService;

    @RequiresPermissions("system:subject:view")
    @GetMapping()
    public String subject()
    {
        return prefix + "/subject";
    }

    /**
     * 查询面试考题记录列表
     */
    @RequiresPermissions("system:subject:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExamSubject examSubject)
    {
        startPage();
        List<ExamSubject> list = examSubjectService.selectExamSubjectList(examSubject);
        return getDataTable(list);
    }

    /**
     * 导出面试考题记录列表
     */
    @RequiresPermissions("system:subject:export")
    @Log(title = "面试考题记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExamSubject examSubject)
    {
        List<ExamSubject> list = examSubjectService.selectExamSubjectList(examSubject);
        ExcelUtil<ExamSubject> util = new ExcelUtil<ExamSubject>(ExamSubject.class);
        return util.exportExcel(list, "面试考题记录数据");
    }

    /**
     * 新增面试考题记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存面试考题记录
     */
    @RequiresPermissions("system:subject:add")
    @Log(title = "面试考题记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExamSubject examSubject)
    {
        return toAjax(examSubjectService.insertExamSubject(examSubject));
    }

    /**
     * 修改面试考题记录
     */
    @RequiresPermissions("system:subject:edit")
    @GetMapping("/edit/{examId}")
    public String edit(@PathVariable("examId") Long examId, ModelMap mmap)
    {
        ExamSubject examSubject = examSubjectService.selectExamSubjectByExamId(examId);
        mmap.put("examSubject", examSubject);
        return prefix + "/edit";
    }

    /**
     * 修改保存面试考题记录
     */
    @RequiresPermissions("system:subject:edit")
    @Log(title = "面试考题记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExamSubject examSubject)
    {
        return toAjax(examSubjectService.updateExamSubject(examSubject));
    }

    /**
     * 删除面试考题记录
     */
    @RequiresPermissions("system:subject:remove")
    @Log(title = "面试考题记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(examSubjectService.deleteExamSubjectByExamIds(ids));
    }
}
